import { fileURLToPath, URL } from 'url'

import { defineConfig } from 'vite'
import cesium from 'vite-plugin-cesium'; // 引入插件
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import ElementPlus from 'unplugin-element-plus/vite'
import qiankun from 'vite-plugin-qiankun'

export default defineConfig(({ command, mode }) => ({
  // 生产环境需要指定运行域名作为base
  base: mode === 'development' ? './' : 'viteDemo',

  plugins: [vue(), vueJsx(),cesium(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    ElementPlus(),
    // 这里的 'myMicroAppName' 是子应用名，主应用注册时AppName需保持一致
    qiankun('viteDemo',{
      useDevMode:true
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '_': fileURLToPath(new URL('./public', import.meta.url))
    }
  },
  server: {
    host: '0.0.0.0',
    port: 3000,
    // 本地启动测试主子应用切换需要在server:{}里面添加headers: {‘Access-Control-Allow-Origin’: ‘*’ }, 解决主应用跳子应用跨域问题
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
  }
}))
